<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String p7bcert=(String)request.getAttribute("p7bcert");
 %>
<SCRIPT LANGUAGE="VBScript">
Sub InstallCert
    Dim errnum
    Dim sz10
    Dim vistasz10
    Dim objXen
    Dim g_objEnroll, g_objPrivateKey, g_objRequest, g_objRequestCMC, g_objCSPInformations, g_certEnrollLoadError


    sz10 = "<%=p7bcert%>"

    On Error Resume Next

	if InStr(Navigator.UserAgent, "Windows NT 6") <> 0 then
		Set g_objEnroll = window.parent.g_objClassFactory.CreateObject("X509Enrollment.CX509Enrollment")
		If 0<>Err.Number Then
			g_certEnrollLoadError = Err.Number
		Else
			g_certEnrollLoadError = 0
		End If
		err.clear
		call g_objEnroll.Initialize(1)					'ContextUser
		err.clear
		call g_objEnroll.Enroll()
		err.clear
		sz10="-----BEGIN PKCS7 CERTIFICATE-----"+sz10+"-----END PKCS7 CERTIFICATE-----"
		call g_objEnroll.InstallResponse( 0, sz10, 3, "" )
	else
	    objXen.DeleteRequestCert = FALSE
    	err.clear
    	objXen.WriteCertToCSP = true
	    objXen.acceptPKCS7(sz10)
	end if

    errnum=err.number

    if err.number <> 0 then
          if err.number = &H800704C7 then
              'MsgBox "The error: " + hex(err.number) + " 在证书安装过程中产生，其原因可能是安装证书时弹出的提示框您选择了“否”！",0,"证书安装失败提示"
              Err.Clear    '清除错误
              window.navigate ("<%=request.getContextPath()%>/jsp/common/CertInstallErr.jsp?flag=800704C7")
              Exit Sub
          elseif  err.number = &H80090020 then
              'MsgBox "The error: " + hex(err.number) + " 在证书安装过程中产生，其原因可能是您选择的证书存储介质空间已满，或您没有正确插入您所使用的证书存储介质！",0,"证书安装失败提示"
              Err.Clear    '清除错误
              window.navigate ("<%=request.getContextPath()%>/jsp/common/CertInstallErr.jsp?flag=80090020")
              Exit Sub
		 elseif  err.number = &H800B0109 then
              'MsgBox "The error: " + hex(err.number) + " 在证书安装过程中产生，其原因可能是您的机器中没有安装建行的根证书，请下载安装建行根证书！",0,"证书安装失败提示"
              Err.Clear    '清除错误
              window.navigate ("<%=request.getContextPath()%>/jsp/common/CertInstallErr.jsp?flag=800B0109")
              Exit Sub
 		 elseif  err.number = &H800B0101 then
              'MsgBox "The error: " + hex(err.number) + " 其原因可能是您的机器中时间设置不正确,请调整您的系统时间！",0,"证书安装失败提示"
              Err.Clear    '清除错误
              window.navigate ("<%=request.getContextPath()%>/jsp/common/CertInstallErr.jsp?flag=800B0101")
              Exit Sub
          else
              'MsgBox "The error: " + hex(err.number) + " 在证书安装过程中产生，其原因可能是您选择的证书存储介质空间已满，或您没有正确插入您所使用的证书存储介质！",0,"证书安装失败提示"
              Err.Clear    '清除错误
              window.navigate ("<%=request.getContextPath()%>/jsp/common/CertInstallErr.jsp?flag=8010000C&ErrorNum="&errnum)
              Exit Sub
          end if
    end if

  End Sub
</SCRIPT>
<html>
<head>
<title></title>
<link href="<%=request.getContextPath()%>/css/style.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
<br><br><br><br><br>
<table width='322' border='0' cellspacing='0' cellpadding='0'
	align='center'>
	<tr>

		<td><img src='<%=request.getContextPath()%>/images/pic_notice_top.jpg' width='322' height='13'></td>
	</tr>
	<tr>
		<td background='<%=request.getContextPath()%>/images/pic_notice_bg.jpg' height='100'>
		<div align='center'>

		<table width='250' border='0' cellspacing='2' cellpadding='0'>
			<tr>
				<td class='' valign=middle><table><tr><td><img src='<%=request.getContextPath()%>/images/succse.gif' width='26'
					height='26'></td><td >成功</td></tr></table></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td class='txt' >
				    证书下载安装成功！
				</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
			</tr>
		</table>
		</div>
		</td>
	</tr>
	<tr>
		<td><img src='<%=request.getContextPath()%>/images/pic_notice_bottom.jpg' width='322' height='12'></td>
	</tr>
</table>
</body>
</html>
<SCRIPT Language="VBScript">
  Call InstallCert
</SCRIPT>